package com.yksj.healthtalk.ui.home;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.yksj.healthtalk.adapter.MySalonListExpandableAdapter.OnClickDeleteListener;
import com.yksj.healthtalk.comm.DeleteOrderBtnFragmentDialog;
import com.yksj.healthtalk.entity.BaseInfoEntity;
import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.ui.R;

public class DeleteOrderBtnFragmentDialogFromMore extends DialogFragment{
	private String orderId;
	private static FragmentActivity f;
	private String id;// 朋友交流就传id

	public static void show(FragmentManager manager, String orderId,
			FragmentActivity f, String id) {
		Fragment fragment = manager.findFragmentByTag("delete");
		FragmentTransaction ft = manager.beginTransaction();
		if (fragment != null) {
			ft.remove(fragment);
		}
		DeleteOrderBtnFragmentDialog dialog = new DeleteOrderBtnFragmentDialog();
		Bundle bundle = new Bundle();
		bundle.putString("orderId", orderId);
		bundle.putString("id", id);
		DeleteOrderBtnFragmentDialogFromMore.f = f;
		dialog.setArguments(bundle);
		ft.add(dialog, "delete");
		ft.commitAllowingStateLoss();
	}

	@Override
	public void onCancel(DialogInterface dialog) {
		super.onCancel(dialog);
		setStyle(DialogFragment.STYLE_NO_TITLE, 0);
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Dialog dialog = new Dialog(getActivity(), R.style.translucent_dialog);
		Bundle bundle = getArguments();
		orderId = bundle.getString("orderId");
		id = bundle.getString("id");
		dialog.setContentView(R.layout.register_dialog);
		TextView message = (TextView) dialog.findViewById(R.id.message);
		Button sureButton = (Button) dialog.findViewById(R.id.sureButton);
		sureButton.setText("删除");
		message.setText("是否确定删除");
		Button cancelButton = (Button) dialog.findViewById(R.id.cancelButton);
		sureButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dismissAllowingStateLoss();
				if (f instanceof FragmentActivity) {
					((OnClickDeleteListener) f).OnClickDelete(null, orderId);
				} else if (f instanceof FragmentActivity) {
					if (!TextUtils.isEmpty(id)) {
						CustomerInfoEntity entity = new CustomerInfoEntity();
						entity.setId(id);
					}
				}
			}
		});

		cancelButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dismissAllowingStateLoss();
			}
		});
		return dialog;
	}
}
